<template>
	<view>
		<zmm-watermark :watermark="userStore.watermark" v-if="userStore.watermark"></zmm-watermark>
		<view class="content detail">
			<!--商品信息-->
			<view class="detail-item">
				<uni-section title="商品信息" type="line"></uni-section>
				<view class="detail-content">
					<view class="detail-text">
						商品编码：
						<text>{{info.code}}</text>
						<text class="detail-text-copy" @click="copyText(info.code)">复制</text>
					</view>
					<view class="detail-text">
						商品名称：
						<text>{{info.name}}</text>
						<text class="detail-text-copy" @click="copyText(info.name)">复制</text>
					</view>
				</view>
			</view>
			<!--销售记录-->
			<view class="detail-item">
				<uni-section :title="startTime&&endTime?`${startTime}至${endTime}${type==2?'出库记录':'销售记录'}`:`${type==2?'出库记录':'销售记录'}`" type="line"></uni-section>
				<view class="detail-content table">
					<ty-table
						:data="tableList"
						:columns="columns"
						:sortable="true"
						:cellClassName="() => 'table-cell'"
						:headerCellClassName="() => 'table-cell'"
						:rowClassName="() => 'table-row'"
						stripe
						border>
						<template v-slot:before="{ row }">
							<view class="table-td-before table-cell table-td-row">
								<view class="table-td-row">
									订单编号：
									<text class="table-td-text">{{row.orderNumber}}</text>
									<text class="detail-text-copy" @click="copyText(row.orderNumber)">复制</text>
								</view>
								<view class="table-td-row">
									下单时间：
									<text class="table-td-text">{{row.createTime}}</text>
								</view>
							</view>
						</template>
						<template v-slot:left="{ row }">
							<view class="table-td-cell">
								<view class="table-td-row">
									发货仓库：
									<text class="table-td-text">{{row.warehoseuName}}</text>
								</view>
								<view class="table-td-row">
									客户姓名：
									<text class="table-td-text">{{row.customerName}}</text>
								</view>
								<view class="table-td-row">
									客户店铺：
									<text class="table-td-text">{{row.company}}</text>
								</view>
							</view>
						</template>
						<template v-slot:right="{ row }">
							<view class="table-td-cell">
								<view class="table-td-row">
									购买数量：
									<text class="table-td-text">{{row.number}}</text>
								</view>
								<view class="table-td-row" v-if="checkPermi(['zhouyz:salesSummary:price'])">
									销售总价：
									<text class="table-td-text">{{row.sumMoney}}</text>
								</view>
								<view class="table-td-row" v-if="checkPermi(['zhouyz:salesSummary:price'])">
									销售单价：
									<text class="table-td-text">{{row.price}}</text>
								</view>
							</view>
						</template>
					</ty-table>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script setup>
import { onLoad } from '@dcloudio/uni-app';
import { computed, onMounted, ref } from 'vue';
import { tab, auth, modal } from "@/plugins"
import { getTitle } from "@/utils/getter"
import { checkPermi, checkRole, checkOnlyPermi, checkOnlyRole } from "@/utils/permission"
import { salesSummaryDetail } from "@/api/erp_api/finance"
import { productDetail } from "@/api/erp_api/product"
import { copyText, arrText } from '@/utils/ty.js';
import useUserStore from '@/store/modules/user'

	const userStore = useUserStore()	
	onLoad((option) => {
		type.value = option?.type || ''
		if (type.value == 2) {
			uni.setNavigationBarTitle({
				title: '出库记录'
			})
		}
		if (option.productId) {
			productId.value = option.productId
			startTime.value = option?.startTime || ''
			endTime.value = option?.endTime || ''
			getDetail()
			getProductDetail()
		}
	})
	
	// 数据查询
	const type = ref('')
	const productId = ref('')
	const startTime = ref('')
	const endTime = ref('')
	const info = ref({})
	const tableList = ref([])
	const isLoading = ref(false)
	
	const getDetail = () => {
		const params = {
			id: productId.value
		}
		productDetail(params).then(res => {
			info.value = res.data || {}
	  })
	}
	
	// 表格头部
	const columns = ref([
		{ title: '订单信息', key: 'left' },
		{ title: '数量金额', key: 'right' }
	])
	
	const getProductDetail = () => {
		const params = {
			productId: productId.value,
			startTime: startTime.value,
			endTime: endTime.value
		}
		isLoading.value = true
		uni.showLoading({
			title: '数据加载中...'
		})
		salesSummaryDetail(params).then(res => {
			tableList.value = res.data || []
			isLoading.value = false
			uni.hideLoading()
    }).catch(() => {
			isLoading.value = false
			uni.hideLoading()
		})
	}
	
</script>

<style scoped>
</style>
